package yannuo.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/javaee2")
public class JavaEE_Request_Session_ServletContext1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Credentials", "true");

        String req = (String) request.getAttribute("req");
        System.out.println("req = " + req);
        request.getSession().invalidate();
        String sess = (String) request.getSession().getAttribute("sess");
        System.out.println("sess = " + sess);
        String con = (String) request.getServletContext().getAttribute("context");
        System.out.println("con = " + con);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
